﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LTJ.Entity;
using LTJ.Data;
using LTJ.Common;
using LTJ.FrameWork;

namespace uswinweb.admin
{
    public partial class usermanage_add :AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (SASRequest.IsPost())
            {
                AddUser();
            }
        }
        protected void AddUser()
        {
            string lname = SASRequest.GetFormString("uLnametxt");
            string rname = SASRequest.GetFormString("uRnametxt");
            string ename = SASRequest.GetFormString("uEnametxt");
            string email = SASRequest.GetFormString("uEamiltxt");
            int gid = SASRequest.GetFormInt("group_hidd_luffy", 0);
            int cid = SASRequest.GetFormInt("comp_hidd_luffy", 0);
            string pwd = SASRequest.GetFormString("uPwdtxt");
            string authority = "";
            if (SASRequest.GetString("authority1") != "")
            {
                authority += SASRequest.GetString("authority1") + ",";
            }
            if (SASRequest.GetString("authority2") != "")
            {
                authority += SASRequest.GetString("authority2") + ",";
            }
            if (SASRequest.GetString("authority3") != "")
            {
                authority += SASRequest.GetString("authority3") + ",";
            }
            LTJ.Entity.UserInfo newuserInfo = new LTJ.Entity.UserInfo();
            newuserInfo.email = email;
            newuserInfo.ename = ename;
            newuserInfo.gid = gid;
            newuserInfo.ip = LTJ.Common.Utils.GetRealIP();
            newuserInfo.lname = lname;
            newuserInfo.pass = LTJ.Common.Utils.MD5(pwd);
            newuserInfo.rname = rname;
            newuserInfo.status = 1;
            newuserInfo.cid = cid;
            newuserInfo.authority = authority.Trim(',');
            int msg = LTJ.FrameWork.Users.CreateUser(newuserInfo);
            if (msg > 0)
            {
                base.RegisterStartupScript("PAGE", "parent.document.getElementById('reclick').click();parent.Lightview.hide();");
            }
            else
            {
                if (msg == -1)
                {
                    base.RegisterStartupScript("PAGETEMPLATE", "此用户名已存在！");
                }
                else
                {
                    base.RegisterStartupScript("PAGETEMPLATE", "用户添加失败！");
                }
            }
        }
    }
}